package com.casic.ops.entity.dto.pipeline.datastructure.event;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 事件处理器注册器的配置类，该类的作用主要是在程序启动的时候，就初始化把带有EventHandler注解的事件处理器注册到Eventhub
 * @author cww
 * @date 2022、6、17
 */
@Service
public class EventRegisterConfig implements InitializingBean {

    @Resource
    private EventRegister eventRegister;
    @Resource
    private ApplicationContext applicationContext;

    @Override
    public void afterPropertiesSet() {
        Map<String, Object> eventHandlerBeans = applicationContext.getBeansWithAnnotation(EventHandler.class);
        eventHandlerBeans.values().forEach(
                eventHandler -> eventRegister.doRegistration((EventHandlerI) eventHandler)
        );
    }
}
